package com.example.myapplication8;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class BookAdapter extends ArrayAdapter<Book> {
    private int resourceId;
    public BookAdapter(Context context, int textViewResourcedId, List<Book> objects){
        super(context,textViewResourcedId,objects);
        resourceId = textViewResourcedId;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Book book = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        TextView bookName = view.findViewById(R.id.book_name);
        TextView bookPrice = view.findViewById(R.id.book_price);
        TextView bookType = view.findViewById(R.id.book_type);
        bookName.setText(book.getName());
        bookPrice.setText(book.getPrice() + "");
        bookType.setText(book.getBooktype() + "");
        return view;

    }
}